﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using InformationExtraction.Utils;
using InformationExtraction.Interface;
using InformationExtraction.Common;

namespace InformationExtraction
{
    class InformationExtractor
    {
        private FileEnumerater fileEnumerater = null;

        /// <summary>
        /// 特征抽取器
        /// 
        /// 使用featureExtraction中指定的特征抽取器提取Directory目录列表下的所有文件并将结果输出到outputFileName文件中
        /// 注意：
        ///   在调用Extract()之前必须制定带抽取文件所在目录，即对Directory赋值
        /// </summary>
        /// <param name="featureExtraction">对应于特定类型信息的特征抽取器</param>
        /// <param name="outputFileName">特征向量的文件名称</param>
        public InformationExtractor(IFeatureExtractable featureExtraction, string outputFileName)
        {
            fileEnumerater = new FileEnumerater(new FileFeatureExtracter(featureExtraction));
            fileEnumerater.SetOutput(outputFileName);
        }

        /// <summary>
        /// 待抽取文件所在文件夹列表
        /// 
        /// </summary>
        public List<string> Directory
        {
            /*
            get
            {
                if (fileEnumerater == null)
                    return null;

                List<string> dirs = new List<string>();
                foreach (DirectoryInfo d in fileEnumerater.DirInfos)
                {
                    dirs.Add(d.Name);
                }

                return dirs;
            }
            */
            set
            {
                if (fileEnumerater == null)
                    return;

                fileEnumerater.DirInfos = new List<DirectoryInfo>();
                DirectoryInfo dir = null;
                foreach (string s in value)
                {
                    dir = new DirectoryInfo(s);
                    fileEnumerater.DirInfos.Add(dir);
                }
            }
            
        }

        /// <summary>
        /// 开始提取文本特征
        /// </summary>
        public void Extract()
        {
            try
            {
                fileEnumerater.Exec();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
            
        }

    }
}
